#include "HdmioutControlManager.h"
#include "Protocol/ProtocolApi.h"
#include "log.h"
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/stat.h>




extern "C"
{
    int VIDEO_HdmioutControl(uint8_t cmd);
}


using namespace Protocol;



HdmioutControlManager::Ptr HdmioutControlManager::Instance(){
    static auto ptr = std::make_shared<HdmioutControlManager>();
    return ptr;
}


HdmioutControlManager::HdmioutControlManager(){
    RegistRPC();
}

HdmioutControlManager::~HdmioutControlManager(){

}

void HdmioutControlManager::RegistRPC(){
    IProtocolInterface::GetInstance()->AuditoryworksRegistRequestRpc("setHdmiScreen", 
        [this](const Json::Value& req_params, Json::Value& res_result, std::string& errinfo){
            return setHdmiScreen(req_params, res_result, errinfo);
        });
}


bool HdmioutControlManager::setHdmiScreen(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo){
    LOG_PrintWarn("-------------------------------------------------------setHdmiScreen %s\n", req_params.toStyledString().c_str());
    if(req_params["ScreenMode"].asBool()){
        VIDEO_HdmioutControl(3);
    }else{
        VIDEO_HdmioutControl(2);
    }
    return true;
}